package com.tjsinfo.tjsoa.system.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.bo.ISystemDutyBo;
import com.tjsinfo.tjsoa.system.vo.TSystemDuty;
/**
 * 更新职位表单
 * @author 岳晓磊
 *
 */
public class UpdateDutyAction extends Action {
	private ISystemDutyBo systemDutyBo; 
	public void setSystemDutyBo(ISystemDutyBo systemDutyBo) {
		this.systemDutyBo = systemDutyBo;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {	
			String dutyId = request.getParameter("dutyId");
			String dutyName = request.getParameter("dutyName");
			String dutyDes = request.getParameter("dutyDes");
			
			TSystemDuty tsd = systemDutyBo.findById(dutyId);
			tsd.setDutyName(dutyName);
			tsd.setDutyDescription(dutyDes);
			
			if(request.getParameter("jibie") != null && !"".equals(request.getParameter("jibie")))
			{
				Integer levelNo = Integer.parseInt(request.getParameter("jibie"));
				tsd.setLevelNo(levelNo);
			}
			else{
				tsd.setLevelNo(null);
			}
			systemDutyBo.update(tsd);
			request.setAttribute("linkurl", "system/duty/dutylist.jsp?fanhui=true");
			request.setAttribute("message", "system.dutyUpdate.message");
			return mapping.findForward("success");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("Exception", e);
			return mapping.findForward("failed");
		}
	}
}
